/** 
 * DefaultURLTitleParser.java Created by iweerarathna on Aug 30, 2011.
 * 
 * Copyright (c) 2011 Virtusa Corporation. All Rights Reserved.<br><br>. 
 * 
 */
package org.uim.cricket.analyzer.parsers.misc.impl;

import org.uim.cricket.analyzer.parsers.misc.URLTitleParsable;

/**
 * Class which parse the given <code>title</code> attribute of a HTML
 * and finds for the short name of a player. This class finds the given
 * String instance against a " profile for " text and assuming the
 * successor substring is indicating the short name of the player. If
 * the input parameter is <code>null</code> or length is zero, then
 * a <code>null</code> String object will be returned.
 * 
 * <p>As an example, suppose input parameter is 
 * "View profile for Isuru Madushanka" then it returns the substring
 * "Isuru Madushanka". If the " profile for " substring can't be 
 * found within given String, it returns input parameter without
 * any changes.
 * 
 * @version 
 * @author iweerarathna
 */
public class DefaultURLTitleParser implements URLTitleParsable {
    
	/**
	 * The text which separates the short name which will assumed
	 * the successor substring for this string value.
	 */
	public static String DELIMETER_OF_SHORTNAME = " profile for ";
	
    @Override
    public String parseUrlTitle(String source) {
        if (source == null || source.length() == 0) return null;
        
        int pos = source.indexOf(DELIMETER_OF_SHORTNAME);
        if (pos < 0) return source;

        return source.substring(pos + DELIMETER_OF_SHORTNAME.length()).trim();
    }

}
